9bb78508
@@ -30,6 +30,7 @@
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.Map.Entry;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.hive.ql.exec.SerializationUtilities;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -589,6 +590,24 @@
protected void pushProjectionsAndFilters(JobConf jobConf, Class inputFormatClass
       splitPathWithNoSchema, false);
   }
 
+  private static boolean isMatch(String splitPath, String key) {
+    if (splitPath.equals(key)) {
+      return true;
+    }
+    // Take care of these cases:
+    //    splitPath:  hdfs://ns/user/hive/warehouse/src/data.txt
+    //    key:        [hdfs://ns]/user/hive/warehouse/src
+    //                [hdfs://ns]/user/hive/warehouse/src_2
+    //                [hdfs://ns]/user/hive/warehouse/src/
+    //                [hdfs://ns]/user/hive/warehouse/src/data.txt
+    key = StringUtils.removeEnd(key, "/");
+    int index = splitPath.indexOf(key);
+    if (index == -1) {
+      return false;
+    }
+    return splitPath.substring(index).equals(key) || splitPath.charAt(index+key.length()) == '/';
+  }
+
   protected void pushProjectionsAndFilters(JobConf jobConf, Class inputFormatClass,
       String splitPath, String splitPathWithNoSchema, boolean nonNative) {
     if (this.mrwork == null) {
@@ -618,8 +637,7 @@
protected void pushProjectionsAndFilters(JobConf jobConf, Class inputFormatClass
         // subdirectories.  (Unlike non-native tables, prefix mixups don't seem
         // to be a potential problem here since we are always dealing with the
         // path to something deeper than the table location.)
-        match =
-          splitPath.startsWith(key) || splitPathWithNoSchema.startsWith(key);
+        match = isMatch(splitPath, key) || isMatch(splitPathWithNoSchema, key);
       }
       if (match) {
         ArrayList<String> list = entry.getValue();
